package com.lihao.wanandroid.ui.tree

import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.lihao.jetpackcore.base.BaseViewModel
import com.lihao.jetpackcore.ext.request
import com.lihao.jetpackcore.state.ResultState
import com.lihao.wanandroid.data.AppRepository
import com.lihao.wanandroid.data.model.ArticleResponse
import com.lihao.wanandroid.data.model.BasePageResponse
import com.lihao.wanandroid.data.model.TreeResponse

/**
 * 知识体系
 */
class TreeViewModel(application: Application) : BaseViewModel(application) {

    val treeData: MutableLiveData<ResultState<ArrayList<TreeResponse>>> = MutableLiveData()

    val articleData: MutableLiveData<ResultState<BasePageResponse<ArticleResponse>>> =
        MutableLiveData()

    var curTabIndex = 0

    var pageNo = 0

    var cid = 0

    var treeList = mutableListOf<TreeResponse>()

    fun getTree() {
        request({ AppRepository.getTree() }, treeData)
    }

    fun getArticleData(pageNo: Int = 0, cid: Int) {
        this.pageNo = pageNo
        this.cid = cid
        request({ AppRepository.getTreeArticle(pageNo, cid) }, articleData)
    }
}